{include file="public/head" /}
  
  <body>
    <div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">后台管理</a>
        <a href="">物业管理系统</a>
        <a>
          <cite>发票列表</cite></a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    </div>
    <div class="x-body">
      <div class="layui-row">
        <form class="layui-form layui-col-md12 x-so"  method="get" action="{url('invoiceList')}">
          <!--<input type="text" name="foundkeycommunity"  placeholder="搜索小区" autocomplete="off" class="layui-input" value="" id="foundkeycommunity" >-->
          <div class="layui-input-inline">
            <select name="community_id" lay-filter="community_id" id="community_id">
              <option value="">所属小区</option>
              {foreach $communitylist as $name}
              <option value="{$name.community_id}" {if isset($community_id)}{if $community_id == $name.community_id}selected{/if}{/if}>{$name.community_name}</option>
              {/foreach}
            </select>
          </div>

          <div class="layui-input-inline"  style="width:100px">
            <select name="group" id="group" lay-filter="group" style="width:90px">
              <option value="">组团</option>
              {if isset($groups)}
              {foreach $groups as $gro}
              <option value="{$gro}" {if isset($group)}{if $gro == $group}selected{/if}{/if}>{$gro}</option>
              {/foreach}
              {/if}
            </select>
          </div>

          <div class="layui-input-inline"  style="width:100px">
            <select name="building" id="building" lay-filter="building" style="width:90px">
              <option value="">楼栋</option>
              {if isset($buildings)}
              {foreach $buildings as $build}
              <option value="{$build}" {if isset($building)}{if $build == $building}selected{/if}{/if}>{$build}</option>
              {/foreach}
              {/if}
            </select>
          </div>
          <div class="layui-input-inline"  style="width:100px">
            <select name="unit" id="unit"  lay-filter="unit" style="width:90px">
              <option value="">单元</option>
              {if isset($units)}
              {foreach $units as $uni}
              <option value="{$uni}" {if isset($unit)}{if $uni == $unit}selected{/if}{/if}>{$uni}</option>
              {/foreach}
              {/if}
            </select>
          </div>
          <div class="layui-input-inline" style="width:100px">
            <select name="room" id="room" style="width:90px">
              <option value="">房间号</option>
              {if isset($rooms)}
              {foreach $rooms as $roo}
              <option value="{$roo}" {if isset($room)}{if $roo == $room}selected{/if}{/if}>{$roo}</option>
              {/foreach}
              {/if}
            </select>
          </div>
          <!--<input type="text" name="owner_name"  placeholder="业主姓名" autocomplete="off" class="layui-input" value="{if isset($owner_name)}{$owner_name}{/if}">
          <input type="text" name="owner_phone"  placeholder="业主电话" autocomplete="off" class="layui-input" value="{if isset($owner_phone)}{$whereroom.owner_phone}{/if}">
           <input type="text" name="acct_period"  placeholder="账期" autocomplete="off" class="layui-input" value="{if isset($acct_period)}{$acct_period}{/if}">-->
          <div class="layui-input-inline">
              <select name="cost_type">
                <option value="">费用类型</option>
                {foreach $costtype as $type}
                <option value="{$type.type}" {if isset($where.cost_type)}{if $where.cost_type == $type.type}selected{/if}{/if}>{$type.type}</option>
                {/foreach}
              </select>
          </div>
          
        
           <div class="layui-input-inline">
            <select name="invoice_type">
              <option value="">发票状态</option>
              <option value="1" {if isset($invoice_type)}{if $invoice_type == '1'}selected{/if}{/if}>已开票</option>
              <option value="3" {if isset($invoice_type)}{if $invoice_type == '3'}selected{/if}{/if}>未开票</option>
              <option value="2" {if isset($invoice_type)}{if $invoice_type == '2'}selected{/if}{/if}>已退票</option>
            </select>
          </div>
         
          <input class="layui-input" placeholder="开始时间" name="gmt_payment_start" id="start" {if isset($gmtstart)}value="{$gmtstart}"{/if}>
          <input class="layui-input" placeholder="结束时间" name="gmt_payment_end" id="end" {if isset($gmtend)}value="{$gmtend}"{/if}>
          <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
        </form>
      </div>
      <xblock>
       
       
        
        <button class="layui-btn" onclick="invoice()"><i class="layui-icon"></i>开发票</button>

        <button class="layui-btn layui-btn-normal" onclick="invoiceExportExcel('{$export}')"><i class="layui-icon"></i>批量导出</button>
        <span style="color:red">*缴费完成选择需要开票的帐单实现开票功能</span>
         {if $Think.session.usertype=="0"}
        <!--<button class="layui-btn " onclick="onekeyBillList2()"><i class="layui-icon"></i>一键收款2</button>-->
        {/if}
        <span class="x-right" style="line-height:40px">账单总金额： {$billsum}  元 &nbsp;&nbsp;&nbsp;&nbsp; 共有数据： {$number}  条</span>
      </xblock>
      <table class="layui-table"  id="table">
        <thead>
          <tr>
            <th style="text-align: center; font-size: 16px;">
              <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align: center; font-size: 16px;">小区名称</th>
            <th style="text-align: center; font-size: 16px;">完整门牌</th>
            <th style="text-align: center; font-size: 16px;">业主姓名</th>
            <th style="text-align: center; font-size: 16px;">手机</th>
            <th style="text-align: center; font-size: 16px;">费用类型</th>
            <th style="text-align: center; font-size: 16px;">账期</th>
            <th style="text-align: center; font-size: 16px;">应收金额</th>
           
           
           
            <th style="text-align: center; font-size: 16px;">付款类型</th>
            <th style="text-align: center; font-size: 16px;">付款时间</th>
            <th style="text-align: center; font-size: 16px;">账单状态</th>
            <th style="text-align: center; font-size: 16px;width: 5%">发票状态</th>
            <th style="text-align: center; font-size: 16px;width: 5%">开票时间</th>
           
            <th style="text-align: center; font-size: 16px;width: 20%">操作</th>
            </tr>
        </thead>
        <tbody>
          {foreach $list as $val}
          <tr>
            <td style="text-align: center;">
              <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id='{$val.id}'><i class="layui-icon">&#xe605;</i></div>
            </td>
            <td style="text-align: center;">{$val.community_id}</td>
            <td style="text-align: center;">{$val.room_address}</td>
            <td style="text-align: center;">{$val.owner_name}</td>
            <td style="text-align: center;">{$val.owner_phone}</td>
            <td style="text-align: center;">{$val.cost_type}</td>
            <td style="text-align: center;">{$val.acct_period}</td>
            <td style="text-align: center;">{$val.bill_entry_amount}</td>
            <!--<td style="text-align: center;">{$val.discount_money}</td>-->
            
            <!--<td style="text-align: center;">{$val.deadline}</td>-->
            <td style="text-align: center;">{$val.pay_type}</td>
            <td style="text-align: center;">
              {if $val.status == 'TRADE_SUCCESS'}
              {$val.gmt_payment}
              {/if}
            </td>
            <td style="text-align: center;">
              {if $val.status == 'TRADE_SUCCESS'}
                已付款
              {elseif $val.status == 'UNDER_PAYMENT'}
                待支付
              {elseif $val.status == 'WAIT_PAYMENT'}
                待付款
              {elseif $val.status == 'OUT_OF_DATE'}
                已逾期
              {/if}
            </td>
           
            <!--<td style="text-align: center;">{$val.ticket}</td>
            <td style="text-align: center;">{$val.invoice_serial_num}</td>-->
            <td style="text-align: center;">
              {if $val.invoice_type == '1'}
                已开发票
              {elseif $val.invoice_type == '2'}
                已退票
              {else}
              {/if}
            </td>
            <td style="text-align: center;">
              {if $val.invoiceTime != '0'}
                {$val.invoiceTime|date="Y-m-d H:i:s",###}
              {/if}
            </td>
            <!--<td style="text-align: center;">{$val.remarks}</td>-->
            <td class="td-manage" style="text-align: center;">
             
              {if $val.invoice_type == 1 ||  $val.invoice_type == 2}
              <button class="layui-btn" onclick="x_admin_show('查看发票','{:url('admin/invoice/CheckEInvoice')}?id={$val.id}',900,700)">查看</button>
              <!--<a title="查看发票"  onclick="x_admin_show('查看发票','{:url('admin/invoice/CheckEInvoice')}?id={$val.id}',900,700)" href="javascript:;">
                <i class="layui-icon">&#xe64a;</i>
              </a>-->
              {/if}
              {if $val.invoice_type == 1}
              <!--<a title="冲红"  onclick="x_admin_show('冲红','{:url('admin/Bill/Cancellation')}?id={$val.id}',700,600)" href="javascript:;">
                <i class="layui-icon">&#xe6b2;</i>
              </a>-->
             <!--<button class="layui-btn layui-btn-danger" onclick="cancellation('{$val.id}', '{$val.id}')" id="red{$val.id}">冲红</button>-->
              <!--<a title="冲红" onclick="cancellation('{$val.id}', '{$val.id}')" href="javascript:;" id="red{$val.id}">
                    <i class="layui-icon">&#xe6b2;</i>
                  </a>-->
              {/if}
              {if $val.invoiceCode}
              <button class="layui-btn  layui-btn-normal" onclick="x_admin_show('再次提交','{:url('invoice/delivery')}?id={$val.id}',600,400)">再次提交</button>
              
              
              {/if}
                
                
                
              
				
            </td>
          </tr>
          {/foreach}
        </tbody>
      </table>
      <div class="page">
        <div>
          {$billlist->render()}
        </div>
      </div>

    </div>
    <script>
      layui.use('laydate', function(){
        var laydate = layui.laydate;
        
        //执行一个laydate实例
        laydate.render({
          elem: '#start' //指定元素
          ,format: 'yyyy-MM-dd HH:mm:ss'
        });

        //执行一个laydate实例
        laydate.render({
          elem: '#end' //指定元素
          ,format: 'yyyy-MM-dd HH:mm:ss'
        });
      });
      function cancellation(id, doc){
        if(confirm('是否确定冲红?')) 
        { 

          var url = "{:url('invoice/Cancellation')}?id=" + id
          // console.log(url)
          window.location.href=url
          $('#red' + doc).attr('href', url)
        } 
          return false; 
      }
        //删除
      
      function billDelId(id, doc){
        if(confirm('删除后无法恢复，确定要删除吗?')) 
        { 
          var url = "{:url('billDelId')}?id=" + id
          // console.log(url)
          $('#' + doc).attr('href', url)
        } 
          return false; 
      } 


      


      //批量导出
      function invoiceExportExcel(exportid){
        var datas = $('#table tbody td .layui-form-checked')
        var ids = []
        datas.each(function(index, element){
          var id = $(this).data('id')
          ids.push(id)
        })

        var str = ids.join(',');
        var count = ids.length
        var url = "{:url('admin/bill/invoiceExportExcel')}?id=" + str +'&export=' + exportid
        console.log(url);
        layer.open({
          type: 2,
          title: '批量导出账单',
          shadeClose: true,
          shade: 0.8,
          area: ['80%', '95%'],
          content: url //iframe的url
        }); 
      }



      //批量开票
      function invoice(){
        if(confirm('是否确定开票?')){
          var datas = $('#table tbody td .layui-form-checked')
          var ids = []
          datas.each(function(index, element){
            var id = $(this).data('id')
            ids.push(id)
          })

          var str = ids.join(',');
          var count = ids.length
          var url = "{:url('admin/invoice/invoice')}?id=" + str
          layer.open({
            type: 2,
            title: '批量开票',
            shadeClose: true,
            shade: 0.8,
            area: ['80%', '95%'],
            content: url //iframe的url
          }); 
        }
        
        
      }
    </script>
    <!-- 多条件查询 -->
    <script>

      layui.use(['form'], function() {
          var form = layui.form
          $("#foundkeycommunity").blur(function(){
            var _this = $(this);
            var foundkeycommunity=_this.val();
            //layer.alert(foundkeycommunity);
            var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_name: foundkeycommunity, type: 5}, function(data) {
                  //console.log(data);
                  $('#community_id').html("")
                  var option = "<option value=''>所属小区</option>"
                  $('#community_id').append(option)
                  for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i]["community_id"] + "'>" + data[i]["community_name"] + "</option>"
                  $('#community_id').append(option)
                  }
                  
                  form.render('select')
              })
          })
          form.on('select(community_id)', function(f){
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: f.value, type: 1}, function(data) {
                console.log(data);
                  $('#group').html("")
                  var option = "<option value=''>所有组团</option>"
                  $('#group').append(option)
                  for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#group').append(option)
                  }
                  
                  form.render('select')
              })
              
              $('#community_id').data('community_id', f.value)
          })

          form.on('select(group)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {community_id: community_id, group: f.value, type: 2}, function(data) {
                  $('#building').html("")
                  var option = "<option value=''>所有楼栋</option>"
                  $('#building').append(option)
                  for (var i = 0; i < data.length; i++) {
                      option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                      $('#building').append(option)
                  }
                  $('#group').data('group', f.value)
                  form.render('select')
              })
          })
  
          form.on('select(building)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {building: f.value, community_id: community_id, group: group, type: 3}, function(data) {
              $('#unit').html("")
              var option = "<option value=''>所有单元</option>"
              $('#unit').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#unit').append(option)
              }
              $('#building').data('building', f.value)
              form.render('select')
              })
          })
  
          form.on('select(unit)', function(f){
              var data_community = $('#community_id').data('community_id')
              var get_community = "<?php if (isset($community_id)) { echo $community_id;}?>"
              var community_id = typeof data_community === 'undefined' ? get_community : data_community

              var data_group = $('#group').data('group')
              var get_group = "<?php if (isset($group)) { echo $group;}?>"
              var group = typeof data_group === 'undefined' ? get_group : data_group

              var data_building = $('#building').data('building')
              var get_building = "<?php if (isset($building)) { echo $building;}?>"
              var building = typeof data_building === 'undefined' ? get_building : data_building
      
              var url = "{:url('admin/Roominfo/fetchdata')}"
              $.post(url, {unit: f.value, community_id: community_id, group: group, building: building, type: 4}, function(data) {
              $('#room').html("")
              var option = "<option value=''>所有房间</option>"
              $('#room').append(option)
              for (var i = 0; i < data.length; i++) {
                  option = "<option value='" + data[i] + "'>" + data[i] + "</option>"
                  $('#room').append(option)
              }
              $('#unit').data('unit', f.value)
              form.render('select')
              })
          })
  
      })
  </script>
    <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
  </body>

</html>